package com.joker.web.controller.orange;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.joker.common.core.controller.BaseController;
import com.joker.common.core.domain.R;
import com.joker.orange.domain.bo.PushVideoBo;
import com.joker.orange.service.AcceptPushedDataService;
import com.joker.orange.service.ILongVideoCategoryService;
import com.joker.orange.service.IVideoInfoService;
import com.joker.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 接收推送数据（视频、漫画、小说、动漫）
 *
 * @author Joker
 * @date 2024/6/12 17:16
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/accept/push")
public class AcceptPushedDataController extends BaseController {

    private final AcceptPushedDataService acceptPushedDataService;
    private final ISysConfigService configService;

    /**
     * 接收网格视频数据
     */
    @SaIgnore
    @PostMapping("/acceptPushVideo")
    public R<Void> acceptPushVideo(@RequestBody String gridStr){
        log.info("【acceptPushVideo】的入参：{}", gridStr);
        JSONObject grid = JSONUtil.parseObj(gridStr);
        acceptPushedDataService.acceptPushVideo(grid, "0");
        return R.ok();
    }

    /**
     * 接收短视频数据
     */
    @SaIgnore
    @PostMapping("/acceptPushShortVideo")
    public R<Void> acceptPushShortVideo(@RequestBody String gridStr){
        log.info("【acceptPushShortVideo】的入参：{}", gridStr);
        JSONObject grid = JSONUtil.parseObj(gridStr);
        acceptPushedDataService.acceptPushVideo(grid, "1");
        return R.ok();
    }

    /**
     * 接收动漫数据
     */
    @SaIgnore
    @PostMapping("/acceptPushAnime")
    public R<Void> acceptPushAnime(@RequestBody String gridStr){
        log.info("【acceptPushAnime】的入参：{}", gridStr);
        JSONObject grid = JSONUtil.parseObj(gridStr);
        acceptPushedDataService.acceptPushVideo(grid, "2");
        return R.ok();
    }

    /**
     * 接收小说数据
     */
    @SaIgnore
    @PostMapping("/acceptPushNovel")
    public R<Void> acceptPushNovel(@RequestBody JSONArray jsonArray){
        log.info("【acceptPushNovel】的入参：{}", jsonArray);
        acceptPushedDataService.acceptPushNovel(jsonArray);
        return R.ok();
    }

    /**
     * 接收漫画数据
     */
    @SaIgnore
    @PostMapping("/acceptPushCaricature")
    public R<Void> acceptPushCaricature(@RequestBody JSONArray jsonArray){
        log.info("【acceptPushCaricature】的入参：{}", jsonArray);
        acceptPushedDataService.acceptPushCaricature(jsonArray);
        return R.ok();
    }

    /**
     * 获取文件Url的前缀
     */
    @SaIgnore
    @PostMapping("/queryFileUrl")
    public R<Map<String,Object>> queryFileUrl(){
        Map<String,Object> map = new HashMap<>();
        map.put("fileUrl", configService.selectConfigByKey("file.oss.url"));
        return R.ok(map);
    }

}
